package com.gisocn.onemap.mvp;

import com.gisocn.onemap.mvp.MvpView;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import java.lang.ref.WeakReference;

/* loaded from: classes2.dex */
public class MvpBasePresenter<V extends MvpView> implements MvpPresenter<V> {
    private CompositeDisposable mCompositeSubscription = new CompositeDisposable();
    private WeakReference<V> viewRef;

    @Override // com.gisocn.onemap.mvp.MvpPresenter
    public void start() {
    }

    @Override // com.gisocn.onemap.mvp.MvpPresenter
    public void attachView(V v) {
        this.viewRef = new WeakReference<>(v);
    }

    public V getView() {
        WeakReference<V> weakReference = this.viewRef;
        if (weakReference == null) {
            return null;
        }
        return weakReference.get();
    }

    public final boolean isViewAttached() {
        WeakReference<V> weakReference = this.viewRef;
        return (weakReference == null || weakReference.get() == null) ? false : true;
    }

    @Override // com.gisocn.onemap.mvp.MvpPresenter
    public void detachView() {
        WeakReference<V> weakReference = this.viewRef;
        if (weakReference != null) {
            weakReference.clear();
            this.viewRef = null;
        }
        CompositeDisposable compositeDisposable = this.mCompositeSubscription;
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }

    @Override // com.gisocn.onemap.mvp.MvpPresenter
    public void destroy() {
        if (isViewAttached()) {
            detachView();
        }
    }

    protected void addDisposable(Disposable disposable) {
        this.mCompositeSubscription.add(disposable);
    }
}
